<?php
require_once "init.php";

$errors = RegisterFormValidator::validate($_POST);

if ($errors == null) {

$userName = $_POST["userName"];
$mobileNumber = $_POST["mobileNumber"];

$newUser = new User();
$newUser->setUid($_uid);
$newUser->setMobileNumber($mobileNumber);
$newUser->setUserName($userName);

ServiceFactory::getUserService()->add($newUser);
?>

<fb:redirect url="index.php?_page=contacts" />

<?php

} else {

include_once "view/header.php";

?>

<fb:error>
    <?php
    if (sizeof($errors) == 1){
    ?>
      <fb:message><?php echo $errors[0] ?></fb:message>
<?php
    } else {
?>
    <fb:message>The following error(s) were encountered:</fb:message>
    <ul>
    <?php foreach ($errors as $error) {?>
          <li><?php echo $error ?></li>
    <?php }?>
    </ul>
    <?php
    }
    ?>
</fb:error>

<?php
include_once "form/addUser.php";

}
?>